<template>
	<view class="wrap bg-fff">
        <view class="searchPage bg-fff">
            <u-search placeholder="搜索添加楼盘" :focus="true" :show-action="false" margin="30rpx" @change="searchBtn" @search="searchBtn"></u-search>
            <view class="selects">
                <block v-for="item in houseList" :key="item.id">
                    <view class="house" @click="bindHouse(item)">
                        <view class="col-3e title">{{item.title}}</view>
                        <view class="col-grey font12">{{item.city}} {{item.area}}</view>
                    </view>
                </block>
                <block v-if="loading">
                    <view class="flex"><u-loading mode="flower" :show="loading"></u-loading></view>
                </block>
                <block v-else-if="keyword !== '' && loading == false">
                    <view class="empty flex font13 col-grey">暂无更多</view>
                </block>
            </view>
        </view>
	</view>
</template>

<script>
import { mapState, mapActions } from 'pinia';
import { useIndexStore } from '@/store/index';
import { adviserSearchHouse } from '@/common/api';

export default {
	data() {
		return {
            loading: false,
            houseList: [],
            keyword: '',
            cityCode: ''
		};
	},
	onLoad(options) {
        this.cityCode = this.nowCityCode

        uni.$check_and_login(function(){
        })
	},
	computed: {
        ...mapState(useIndexStore, ['nowCityCode']),
	},
    //分享
    onShareAppMessage(res) {
    	return {
    		title: '邀您入驻顾问之家',
    		path: `/pages/my/adviser/adviser-join?cityCode=${this.cityCode}`,
    	}
    },
	methods: {
        ...mapActions(useIndexStore, ['setAdviserSelectHouse']),
        
        //搜索楼盘
        searchBtn(e){
            const that = this;
            this.keyword = e;
            this.loading = true;
            this.$u.throttle(function() {
                adviserSearchHouse({
                    keyword: e,
                    cityCode: that.cityCode
                }).then(res => {
                    that.loading = false;
                    that.houseList = res.detail;
                })
            }, 500)
        },
        
        //选择楼盘
        bindHouse(info){
            this.setAdviserSelectHouse(info);
            this.houseList = [];
            uni.navigateBack({
                delta: 1
            });
        }
	}
};
</script>

<style scoped lang="scss">
.wrap {
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    line-height: 1;
    .searchPage{
        .selects{
            margin: 30rpx;
            .house{
                padding: 20rpx;
                border-bottom: 1rpx solid rgba(0,0,0,.04);
                &:last-child{
                    border: none;
                }
                .title{
                    margin-bottom: 10rpx;
                }
            }
        }
    }
}
</style>
